use "$out_HS/bno_fekvo_anon_t.dta", clear
keep anon t fekvo_bno
duplicates drop
gen bno_flagSext=.

foreach x in S03 S13 S23 S33 ///
	S40 S41 S42 S43 S44 S45 S46 S49 ///
	S50 S51 S52 S53 S54 S55 S56 S59 ///
	S60 S61 S62 S63 S64 S65 S66 S69 ///
	S70 S71 S72 S73 S74 S75 S76 S79 ///
	S80 S81 S82 S83 S84 S85 S86 S89 ///
	S90 S91 S92 S93 S94 S95 S96 S99 ///
  {
	gen BNO`x' = .
	replace bno_flagSext = 1 if fekvo_bno=="`x'" 
	replace BNO`x' = 1 if fekvo_bno=="`x'" 
	}

gen bno_flagSall=bno_flagSext

foreach x in S00 S01 S02 S04 S05 S06 S07 S08 S09 ///
	S10 S11 S12 S14 S15 S16 S17 ///
	S20 S21 S22 S24 S25 S26 S27 S28 S29 ///
	S30 S31 S32 S34 S35 S36 S37 S38 ///
	S47 S48 S58 S67 S68 S78 S88 S98 ///
  {
	gen BNO`x' = .
	replace bno_flagSall = 1 if fekvo_bno=="`x'" 
	replace BNO`x' = 1 if fekvo_bno=="`x'" 
	}
	
	
egen max_bnoSext = max(bno_flagSext), by(anon t)
egen max_bnoSall = max(bno_flagSall), by(anon t)
foreach var of varlist BNO* {
	egen max_`var' = max(`var'), by(anon t)
	}
	
keep anon t max_bnoSext max_bnoSall max_BNO*
duplicates drop anon t, force
sort anon t
egen num_bnoSext = rowtotal(max_BNOS03 max_BNOS13 max_BNOS23 max_BNOS33 max_BNOS40 max_BNOS41 max_BNOS42 max_BNOS43 max_BNOS44 max_BNOS45 max_BNOS46 max_BNOS49 max_BNOS50 max_BNOS51 max_BNOS52 max_BNOS53 max_BNOS54 max_BNOS55 max_BNOS56 max_BNOS59 max_BNOS60 max_BNOS61 max_BNOS62 max_BNOS63 max_BNOS64 max_BNOS65 max_BNOS66 max_BNOS69 max_BNOS70 max_BNOS71 max_BNOS72 max_BNOS73 max_BNOS74 max_BNOS75 max_BNOS76 max_BNOS79 max_BNOS80 max_BNOS81 max_BNOS82 max_BNOS83 max_BNOS84 max_BNOS85 max_BNOS86 max_BNOS89 max_BNOS90 max_BNOS91 max_BNOS92 max_BNOS93 max_BNOS94 max_BNOS95 max_BNOS96 max_BNOS99) 
egen num_bnoSall = rowtotal(max_BNO*)

lab var 	max_BNOS03	"Dislocation and sprain of joints and ligaments of head	"
lab var 	max_BNOS13	"Dislocation and sprain of joints and ligaments at neck level	"
lab var 	max_BNOS23	"Dislocation and sprain of joints and ligaments of thorax	"
lab var 	max_BNOS33	"Dislocation and sprain of joints and ligaments of lumbar spine and pelvis	"
lab var 	max_BNOS40	"Superficial injury of shoulder and upper arm	"
lab var 	max_BNOS41	"Open wound of shoulder and upper arm	"
lab var 	max_BNOS42	"Fracture of shoulder and upper arm	"
lab var 	max_BNOS43	"Dislocation and sprain of joints and ligaments of shoulder girdle	"
lab var 	max_BNOS44	"Injury of nerves at shoulder and upper arm level	"
lab var 	max_BNOS45	"Injury of blood vessels at shoulder and upper arm level	"
lab var 	max_BNOS46	"Injury of muscle, fascia and tendon at shoulder and upper arm level	"
lab var 	max_BNOS49	"Other and unspecified injuries of shoulder and upper arm	"
lab var 	max_BNOS50	"Superficial injury of elbow and forearm	"
lab var 	max_BNOS51	"Open wound of elbow and forearm	"
lab var 	max_BNOS52	"Fracture of forearm	"
lab var 	max_BNOS53	"Dislocation and sprain of joints and ligaments of elbow	"
lab var 	max_BNOS54	"Injury of nerves at forearm level	"
lab var 	max_BNOS55	"Injury of blood vessels at forearm level	"
lab var 	max_BNOS56	"Injury of muscle, fascia and tendon at forearm level	"
lab var 	max_BNOS59	"Other and unspecified injuries of elbow and forearm	"
lab var 	max_BNOS60	"Superficial injury of wrist, hand and fingers	"
lab var 	max_BNOS61	"Open wound of wrist, hand and fingers	"
lab var 	max_BNOS62	"Fracture at wrist and hand level	"
lab var 	max_BNOS63	"Dislocation and sprain of joints and ligaments at wrist and hand level	"
lab var 	max_BNOS64	"Injury of nerves at wrist and hand level	"
lab var 	max_BNOS65	"Injury of blood vessels at wrist and hand level	"
lab var 	max_BNOS66	"Injury of muscle, fascia and tendon at wrist and hand level	"
lab var 	max_BNOS69	"Other and unspecified injuries of wrist, hand and finger(s)	"
lab var 	max_BNOS70	"Superficial injury of hip and thigh	"
lab var 	max_BNOS71	"Open wound of hip and thigh	"
lab var 	max_BNOS72	"Fracture of femur	"
lab var 	max_BNOS73	"Dislocation and sprain of joint and ligaments of hip	"
lab var 	max_BNOS74	"Injury of nerves at hip and thigh level	"
lab var 	max_BNOS75	"Injury of blood vessels at hip and thigh level	"
lab var 	max_BNOS76	"Injury of muscle, fascia and tendon at hip and thigh level	"
lab var 	max_BNOS79	"Other and unspecified injuries of hip and thigh	"
lab var 	max_BNOS80	"Superficial injury of knee and lower leg	"
lab var 	max_BNOS81	"Open wound of knee and lower leg	"
lab var 	max_BNOS82	"Fracture of lower leg, including ankle	"
lab var 	max_BNOS83	"Dislocation and sprain of joints and ligaments of knee	"
lab var 	max_BNOS84	"Injury of nerves at lower leg level	"
lab var 	max_BNOS85	"Injury of blood vessels at lower leg level	"
lab var 	max_BNOS86	"Injury of muscle, fascia and tendon at lower leg level	"
lab var 	max_BNOS89	"Other and unspecified injuries of lower leg	"
lab var 	max_BNOS90	"Superficial injury of ankle, foot and toes	"
lab var 	max_BNOS91	"Open wound of ankle, foot and toes	"
lab var 	max_BNOS92	"Fracture of foot and toe, except ankle	"
lab var 	max_BNOS93	"Dislocation and sprain of joints and ligaments at ankle, foot and toe level	"
lab var 	max_BNOS94	"Injury of nerves at ankle and foot level	"
lab var 	max_BNOS95	"Injury of blood vessels at ankle and foot level	"
lab var 	max_BNOS96	"Injury of muscle and tendon at ankle and foot level	"
lab var 	max_BNOS99	"Other and unspecified injuries of ankle and foot	"

rename max_BNO* BNO*

		
lab var num_bnoSext "# of bnoSext shocks"
lab var num_bnoSall "# of all bnoS shocks"

save "$out/bnoSext_merge_allS.dta", replace

